package cn.itcast.controller;

import cn.itcast.domain.Dishes;
import cn.itcast.service.UserService;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/dishes")
public class DishesController {
    @Resource
    private UserService service;

    /**
     * 主页模糊查询
     * @return
     */
    @RequestMapping("/findFoodByPage.do")
    @ResponseBody
    public List<Dishes> findFoodByPage(String crux){
        System.out.println(crux);
        List<Dishes> list=new ArrayList<>();
        list=service.findFood(crux);
        return list;
    }

    @RequestMapping("/findallDishes.do")
    @ResponseBody
    public List<Dishes> findFoodByAll(Integer pageNum){
        PageHelper.startPage(pageNum,1);
        List<Dishes> list=new ArrayList<>();
        list=service.findFoodByAll();
        return list;
    }
    @RequestMapping("/deleteDish.do")
    @ResponseBody
    public Map<String,Object> deleteDish(Integer id){
        Map<String,Object> maplist=new HashMap<>();
        String result=null;
        Boolean flag=service.deletedish(id);
        if(flag){
            result="1";
        }else {
            result="0";
        }
        maplist.put("result",result);
        return maplist;
    }


}
